url = 'https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca'

class Solution:
    def ReverseList(self , head: ListNode) -> ListNode:
        # write code here
        if head is None:
            return head
        vals = []
        t = head
        while t is not None:
            vals.append(t)
            t = t.next
        
        new_head = vals.pop()
        t = new_head
        while vals:
            t.next = vals.pop()
            t = t.next
        t.next = None
        return new_head